package com.zbkj.front.controller.merchant;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.TraceableOrderFrontSaveRequest;
import com.zbkj.common.request.TraceableOrderFrontSearchRequest;
import com.zbkj.common.response.OrderNoResponse;
import com.zbkj.common.response.TraceableOrderDetailFrontResponse;
import com.zbkj.common.response.TraceableOrderDetailResponse;
import com.zbkj.common.response.TraceableOrderFrontSearchResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.service.service.TraceableOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 溯源订单 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/merchant/traceable/order")
@Api(tags = "溯源订单控制器", description = "商户购买监控，蓝牙发射器等溯源套餐生成的订单") //配合swagger使用

public class TraceableOrderController {

    @Autowired
    private TraceableOrderService traceableOrderService;

    /**
     * 分页显示溯源订单表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author dazongzi
     * @since 2025-06-26
     */
//    @PreAuthorize("hasAuthority('platform:activitystyle:list')")
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<TraceableOrderFrontSearchResponse>> getList(@Validated TraceableOrderFrontSearchRequest request,
                                                                             @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<TraceableOrderFrontSearchResponse> monitorOrderCommonPage = CommonPage.restPage(traceableOrderService.getListFront(request, pageParamRequest));
        return CommonResult.success(monitorOrderCommonPage);
    }

    @ApiOperation(value = "创建订单")
    @RequestMapping(value = "/user/create", method = RequestMethod.POST)
    public CommonResult<OrderNoResponse> createOrder(@RequestBody @Validated TraceableOrderFrontSaveRequest request) {
        return CommonResult.success(traceableOrderService.createOrder(request));
    }

    /**
     * 查询溯源订单表详情
     * @param id Integer
     * @author dazongzi
     * @since 2025-07-10
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<TraceableOrderDetailFrontResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(traceableOrderService.getDetailsH5(id));
    }

}



